<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>加减计数器</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@3/dist/vue.global.js"></script>
    <style>
        #app {
            display: flex;
            flex-direction: column;
            align-items: center;
            margin-top: 50px;
            font-family: Arial, sans-serif;
        }

        button {
            padding: 10px 20px;
            margin: 5px;
            font-size: 16px;
            cursor: pointer;
        }

        .count {
            font-size: 24px;
            margin: 20px 0;
        }

        .message {
            color: red;
            font-size: 14px;
        }
    </style>
</head>

<body>
    <div id="app">
        <button v-on:click="sub">-</button>
        <span class="count" v-text="num"></span>
        <button v-on:click="add">+</button>
        <div class="message" v-text="message"></div>
    </div>

    <script>
        const { createApp } = Vue;

        createApp({
            data() {
                return {
                    num: 0,
                    message: ""
                };
            },
            methods: {
                add() {
                    if (this.num < 10) {
                        this.num++;
                        this.message = ""; // 清空提示信息
                    } else {
                        this.message = "已经达到最大值！";
                    }
                },
                sub() {
                    if (this.num > 0) {
                        this.num--;
                        this.message = ""; // 清空提示信息
                    } else {
                        this.message = "已经达到最小值！";
                    }
                }
            }
        }).mount('#app');
    </script>
</body>

</html>